package com.bw.module_video_detail.mvi.model.repository

import com.bw.lib_net.BaseResponse
import com.bw.module_video_detail.mvi.model.api.VideoDetailApi
import com.bw.module_video_detail.mvi.model.entity.DanMuEntity
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import retrofit2.http.Query
import javax.inject.Inject

/**
 * @author ytx
 * @date 2025-10-21 10:10
 * @description
 */
class VideoDetailRepository @Inject constructor(val api: VideoDetailApi){
    /**
     * 获得弹幕信息
     */
    fun getBulletScreenInfo(datatype:Int, itemId:String) = flow {
        emit(api.getBulletScreenInfo(datatype, itemId))
    }.flowOn(Dispatchers.IO)

    /**
     * 发送弹幕
     */
    fun publishBulletScreen(danMuEntity: DanMuEntity) = flow {
        val requestBody = Gson().toJson(danMuEntity).toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())
        emit(api.publishBulletScreen(requestBody))
    }.flowOn(Dispatchers.IO)
    /**
     * 修改用户金币
     */
    fun modifyCoinAmount(id:String, nm:Int) = flow {
        emit(api.modifyCoinAmount(id, nm))
    }.flowOn(Dispatchers.IO)
}